from app.libs.redprint import RedPrint
from app.validators.client import ClientForm
from app.validators.user import UserEmailForm
from app.libs.enums import ClientTypeEnum
from app.models.user import User
from app.libs.error_code import Created

api = RedPrint('client')


def __register_by_email():
    form = UserEmailForm().validate_for_api()
    User.register_by_email(form.nickname.data, form.account.data, form.secret.data)


def __register_by_mobile():
    pass


def __register_by_weixin():
    pass


def __register_by_mina():
    pass


@api.route('/register', methods=['POST'])
def create_client():
    """用户注册"""
    form = ClientForm().validate_for_api()
    promise = {
        ClientTypeEnum.USER_EMAIL: __register_by_email,
        ClientTypeEnum.USER_MOBILE: __register_by_mobile,
        ClientTypeEnum.USER_WX: __register_by_weixin,
        ClientTypeEnum.USER_MINA: __register_by_mina,
    }
    promise[form.type.data]()

    return Created()
